using System;
using System.Collections.Generic;
using System.Text;
using ECommerce.Library.DataStructure;
using Entity;
using log4net;
using ECommerce.Library;
using System.Web;
using AutoGear.BLL;
using eShop.Business;
using eShop.DataAccess;


namespace eShop.Model
{
    public class Category
    {
        public int CategoryId { get; set; }
        public string CategoryName
        {
            get { return HttpContext.Current.Server.HtmlDecode(this._categoryName); }
            set { this._categoryName = value; CategoryNameChanged = true; }
        }
        public bool CategoryNameChanged { get; set; }
        public string CategoryTitle
        {
            get { return HttpContext.Current.Server.HtmlDecode(this._categoryTitle); }
            set { this._categoryTitle = value; }
        }
        public string CategoryDescription { get; set; }
        public string CategoryImageUrl { get; set; }
        public string CategoryUrl { get; set; }


        private string _categoryName;
        private string _categoryTitle;
        private Category _parentCategory;



        public string DisplayOrder { get; set; }
        public bool IsFeatured { get; set; }
        public bool IsActive { get; set; }
        public bool IsDeleted { get; set; }
        public DateTime CreateDate { get; set; }
        public int SubCategoryCount { get; set; }
        public Category ParentCategory
        {
            get
            {
                if (this._parentCategory == null && this.ParentCategoryId != this.CategoryId)
                {
                    this._parentCategory = CategoryManager.GetById(this.ParentCategoryId);
                }
                return this._parentCategory;
            }
        }
        public int ProductCount { get; set; }
        public int ParentCategoryId { get; set; }
        public ReadOnlyCustomCollection<Category> SubCategories { get; set; }
        public bool IsSubCategoryLoaded { get; set; }
        public static int RootCategoryId { get; set; }
        public string ProductDisplayOrder { get; set; }
        public string CategoryBannerImageUrl { get; set; }
        public static ReadWriteCustomCollection<Category> RootCategories
        {
            get
            {
                ReadWriteCustomCollection<Category> menuCategory = new ReadWriteCustomCollection<Category>();
                menuCategory = CategoryManager.GetActiveSubCategoriesPaged(RootCategoryId, "displayOrder", 0, 999999);
                return menuCategory;
            }
        }



        public int ActiveSubCategoriesCount
        {
            get { return CategoryDAO.GetActiveSubCategoriesByParentCategoryIdPagedCount(CategoryId); }
        }

        public Category()
        {
            RootCategoryId = SiteUtility.SuperRootCategoryId;
        }
    }
}
